<html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css">
dt {
  font-style: italic;
  margin-top: 15px;
  margin-bottom: 3px;
  margin-left: 0px;
  border-bottom: 1px dotted black;
}
dd {
  margin-left: 10px;
}
table {
  border-collapse:collapse;
  border: 1px solid black;
  margin-top: 7px;
}
th {
  border: 1px solid black;
  padding: 3 7 3 7;
}
td {
  border: 1px solid black;
  padding: 3 7 3 7;
}
</style></head><body><p><a name="newarray"></a><b>newarray</b> :
  allocate new array for numbers or booleans : <a href="opcodes.html">index</a> : <a href="http://asm.objectweb.org/asm40/javadoc/user/org/objectweb/asm/MethodVisitor.html#visitIntInsn(int,%20int)">visitIntInsn()</a></p><dl><dt>Description</dt><dd>newarray is used to allocate single-dimension arrays of
booleans, chars, floats, doubles, bytes, shorts, ints or longs. For example,
when you write the Java code:<br></br><pre>
new int[10];
</pre>
this
is compiled into:<br></br><pre>
bipush 10          ; push the int 10 onto the stack
newarray int       ; make an array of 10 ints. The new array is left on the stack
</pre>
newarray
pops a positive int, n, off the stack, and constructs an array for holding n
elements of the type given by &lt;type&gt;. Initially the elements in the array
are set to zero. A reference to the new array object is left on the stack.</dd><dt>Exceptions</dt><dd>NegativeArraySizeException - n is less than zero.<br></br>OutOfMemoryError - insufficient memory to allocate the array.</dd><dt>Example</dt><dd><pre>
; This is like the Java code:
;     short x[] = new short[2];
iconst_2           ; push 2 onto the stack
newarray short     ; call newarray to make a 2-element short array
astore_1           ; store the reference to the array in local variable 1
</pre></dd><dt>Notes</dt><dd>The Java boolean <b xmlns="">false</b> is represented in the JVM by the integer
0; <b xmlns="">true</b> is represented by the integer 1. Boolean arrays are actually
treated as byte arrays and are initialized to false (0). You should use the
baload and bastore instructions to load and store values in
boolean arrays.</dd><dt>See also</dt><dd><a href="ref-anewarray.html">anewarray</a> <a href="ref-.html"></a> <a href="ref-multianewarray.html">multianewarray</a> <a href="ref-.html"></a> <a href="ref-new.html">new</a> </dd><dt>Stack</dt><dd><table xmlns="">
<tr>
<td>
<b>Before </b>
</td>
<td><b>After</b></td></tr>
<tr>
<td>n</td>
<td>arrayref</td></tr>
<tr>
<td>...</td>
<td>...</td></tr>
</table></dd><dt>Bytecode</dt><dd><table xmlns="">
<tr>
<td>
<b> Type </b>
</td>
<td><b>Description</b></td></tr>
<tr>
<td>
u1 
</td>
<td>newarray
opcode = 0xBC (188)
</td></tr>
<tr>
<td>
u1 
</td>
<td>array-type
(see below)
</td></tr>
</table><br></br>
In bytecode, the type of the array is specified by the array-type byte
immediately following the newarray opcode, which has one of the
following values:
<table xmlns="">
<tr>
<td>
<b>Array Type</b>
</td>
<td><b>Value</b></td></tr>
<tr>
<td>boolean</td>
<td>4</td></tr>
<tr>
<td>char</td>
<td>5</td></tr>
<tr>
<td>float</td>
<td>6</td></tr>
<tr>
<td>double</td>
<td>7</td></tr>
<tr>
<td>byte</td>
<td>8</td></tr>
<tr>
<td>short</td>
<td>9</td></tr>
<tr>
<td>int</td>
<td>10</td></tr>
<tr>
<td>long</td>
<td>11</td></tr>
</table></dd></dl></body></html>